package storeMovie.Util;

import org.hibernate.Session;
import org.hibernate.Transaction;

import storeMovie.JavaBean.AccountBank;

public class AccountBankManager {
	//private Session session = null;

	public AccountBankManager() {
		//session = SessionFactoryUtil.getSessionFactory().getCurrentSession();
		//session.beginTransaction();
	}
	
	public void saveAccountBank(AccountBank accountBank) {
		Session session=null;
		Transaction t=null;
		try{
			session=HibernateUtil.currentSession();
			t=session.beginTransaction();
			session.save(accountBank);
			t.commit();
		}catch (Exception ex) {
			ex.printStackTrace();
			t.rollback();
		}
	}
	public void updateAccountBank(AccountBank accountBank) {
		
		Session session=null;
		Transaction t = null;
		try{
			session = HibernateUtil.currentSession();
			t=session.beginTransaction();
			session.update(accountBank);
			t.commit();
		}catch (Exception e) {
			System.out.println(e.getCause());// TODO: handle exception
			t.rollback();
		}
	}
	
	public AccountBank getAccountBankByName(String username) {
		Session session=null;
		AccountBank accountBank = new AccountBank();
		try{
			session = HibernateUtil.currentSession();
			accountBank = (AccountBank)session.get(AccountBank.class, new String(username));
			return accountBank;
		}catch (Exception e) {
			//System.out.println(e.getCause());// TODO: handle exception
			e.printStackTrace();
		}
		return accountBank;
	}
}
